from datetime import datetime

from flask import Flask, render_template, session, redirect, url_for, flash
from flask_bootstrap import Bootstrap
from flask_moment import Moment

import NameForm as nf

import uuid


app = Flask(__name__)

moment = Moment(app)
bootstrap = Bootstrap(app)
app.config["SECRET_KEY"] =uuid.uuid4().hex


@app.route('/')
def index():
    return render_template('index.html',current_time=datetime.utcnow())


@app.route('/user', methods=['GET', 'POST'])
def user():

    form = nf.NameForm()
    if form.validate_on_submit():
        old_name = session.get('name')
        if old_name is not None and old_name != form.name.data:
            flash('Looks like you have changed your name!')
        session['name'] = form.name.data
        return redirect(url_for('user'))
    return render_template('user.html',form=form, name=session.get('name'))


@app.errorhandler(404)
def page_not_found(e):
    return render_template('404.html'), 404

# this is the main.and no
if __name__ == '__main__':

    app.run(debug=True)
